package la.iok.hzsvn.lewin.movie.shopmovie.controller;

import la.iok.hzsvn.lewin.movie.core.Token;
import la.iok.hzsvn.lewin.movie.core.shopmovie.param.CouponDefinitionListParam;
import la.iok.hzsvn.lewin.movie.core.shopmovie.param.CouponDefinitionParam;
import la.iok.hzsvn.lewin.movie.core.shopmovie.vo.CouponDefinitionVo;
import la.iok.hzsvn.lewin.movie.shopmovie.service.CouponDefinitionService;
import la.iok.hzsvn.lewin.movie.shopmovie.service.CouponService;
import la.iok.hzsvn.lewin.mybatis.model.PageParam;
import la.iok.hzsvn.lewin.mybatis.model.PageVo;
import la.iok.hzsvn.lewin.mybatis.model.SortParam;
import la.iok.hzsvn.share.annotations.NotNull;
import la.iok.hzsvn.share.response.OperatorResponse;
import la.iok.hzsvn.share.response.OperatorResponses;
import la.iok.hzsvn.share.response.SingleDataResponse;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("couponDefinitions")
public class CouponDefinitionController {
    private final CouponDefinitionService couponDefinitionService;
    private final CouponService couponService;

    public CouponDefinitionController(CouponDefinitionService couponDefinitionService,
                                      CouponService couponService) {
        this.couponDefinitionService = couponDefinitionService;
        this.couponService = couponService;
    }

    @PostMapping
    public OperatorResponse save(@RequestHeader Token token, @RequestBody CouponDefinitionParam param){
        couponDefinitionService.save(token, param);
        return OperatorResponses.success();
    }

    @PutMapping("{id}")
    public OperatorResponse modify(@RequestHeader Token token, @PathVariable Long id, @RequestBody CouponDefinitionParam param){
        couponDefinitionService.modify(token, id, param);
        return OperatorResponses.success();
    }

    @DeleteMapping("{id}")
    public OperatorResponse delete(@RequestHeader Token token, @PathVariable Long id){
        couponService.deleteDefinition(token, id);
        return OperatorResponses.success();
    }
    @GetMapping
    public SingleDataResponse<PageVo<CouponDefinitionVo>> page(@RequestHeader Token token, @NotNull PageParam pageParam,
                                                               @NotNull SortParam sortParam, @NotNull CouponDefinitionListParam listParam){
        return new SingleDataResponse<>(couponDefinitionService.page(token, pageParam, sortParam, listParam));
    }
}
